<?php

/**
 * @author sunqiang
 */

namespace App\Repositories;

use App\Models\Adminuser;

/**
 * 权限仓库
 */
class AdminuserRepository
{
    //列表
    public function list($where = []) 
    {
        return Adminuser::where($where)->get();
    }

    //分页列表
    public function pageList($where = [])
    {
        if (!isset($where['page'])) {
            $where['page'] = 15;
        }

        return $userList = Adminuser::orderBy('created_at', 'desc')->where(function ($query) use ($where) {
            if (isset($where['search'])) {
                $query->Where('name', 'like', '%' . $where['search'] . '%')
                      ->orWhere('mobile', 'like', '%' . $where['search'] . '%');
            }
            if (isset($where['type'])) {
            $query = $query->where('type',$where['type']);
             }

           
        })->paginate($where['page']);

    }


    //新增
    public function create($param)
    {
        $sys = new Adminuser();
        $param['password'] = md5($param['password']);
        $sys->fill($param)->save();
        return $sys->id;
    }
    //更新
    public function update($param)
    {
        $sys = Adminuser::find($param['id']);
        return $sys->fill($param)->save();
    }
    //删除
    public function delete($id)
    {
        return Adminuser::where('id', $id)->delete();
    }
    //权限详情
    public function info($id)
    {
        return Adminuser::where('id', $id)->first();
    }
    //权限详情
    public function username($username)
    {
        return Adminuser::where('username', $username)->first();
    }
    public function infoBytoken($token)
    {
        return Adminuser::select('id', 'name', 'token_time')->where('login_token', $token)->first();
    }

}
